package com.month.order.controller;

import com.month.order.bean.Order;
import com.month.order.properties.OrderProperties;
import com.month.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope // 动态刷新配置
@RestController
public class OrderController {


    @Autowired
    OrderService orderService;


    @Autowired
    OrderProperties orderProperties;


    @GetMapping("/getConfig")
    public String getConfig(){
        return "超时时间:"+orderProperties.getTimeout() +
                " 确认时间:"+orderProperties.getAutoConfirm()+
                "数据库地址:"+orderProperties.getDateBase();
    }


    @GetMapping("/createOrder")
    public Order createOrder(@RequestParam("productId") Long productId,
                             @RequestParam("userId") Long userId){

        return orderService.createOrder(productId,userId);
    }
}
